package com.shopcentre15.shopcentre.FormalShopExplot.Service.Impl.Consumer;

import com.shopcentre15.shopcentre.FormalShopExplot.Dao.Consumer.ConsumerDao;
import com.shopcentre15.shopcentre.FormalShopExplot.Entity.ShopConsumer;
import com.shopcentre15.shopcentre.FormalShopExplot.Service.Consumer.ConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ConsumerServiceImpl implements ConsumerService {
    @Autowired
    private ConsumerDao consumerDao;

    @Override
    public Integer register(ShopConsumer shopConsumer) {
        if(shopConsumer.getAccount() == null){
            return 0;
        }
        ShopConsumer consumer = getConsumer(shopConsumer.getAccount());
        if(consumer == null){
            return consumerDao.register(shopConsumer);
        }
        return 0;
    }

    @Override
    public ShopConsumer getConsumer(String account) {
        if(account == null){
            return null;
        }
        return consumerDao.getConsumer(account);
    }

    @Override
    public ShopConsumer login(ShopConsumer shopConsumer) {
        if(shopConsumer.getAccount() != null || shopConsumer.getPassword() != null){
            return consumerDao.login(shopConsumer);
        }
        return null;
    }

    @Override
    public Integer updateConsumer(ShopConsumer shopConsumer) {
        String account = shopConsumer.getAccount();
        if(account == null){
            return 0;
        }
        return consumerDao.updateConsumer(shopConsumer);
    }
}
